<?php
class LoginAction extends  Action {
	function Login()
	{
		if(getUserId()!=0){
			$this->assign('jumpUrl',U("/Index/main"));
			$this->success("已登录");
			return ;
		}
		
		if(!$this->isPost()){
			$this->display('login');
		}else{
			$username=trim($_REQUEST['username']);
			$password=trim($_REQUEST['password']);
			
			if($user=checkUser($username, $password)){
				//登录成功
				//print_r($user);
				setUser($user);
				$this->assign('jumpUrl',U("/Index/main"));
				$this->success("登录成功!");
			}else{
				$this->error("用户名或密码错误!");
			}
		}
	}
	
	function logout()
	{
		unsetUser();
		$this->jumpUrl=U("/Login/login");
		$this->success("您已安全退出!");
	}
}